
// 节流
const shake = (fn, wait) => {
  let previous = 0
  return function() {
    const now = Date.now()
    const _this = this
    // const args = arguments
    if (now - previous > wait) {
      fn.apply(_this, arguments)
      previous = now
    }
  }
}

// 防抖
const dedounce = (func, delay) => {
  let timeout
  return function() {
    const arg = arguments
    if (timeout) clearTimeout(timeout)
    timeout = setTimeout(() => {
      func(arg)
    }, delay)
  }
}

module.exports = { dedounce, shake }
